<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
  <title>学术</title>
  <style>
		html, body {width: 100%;min-height: 100%;background: #f0f0f0;}
    .h20 {height: 0.5rem;background: #f0f0f0;}

    .xhList ul {
      background: #f0f0f0;
    }
    .xhList .aui-list-item {
      background: #fff;
      margin: 0.5rem 0;
    }
    #app {
      min-height: calc(100vh - 65px);
    }
	</style>
</head>
<body>
  <section class="aui-refresh-content">
      <div class="aui-content">
          <div id="demo">
<div class="aui-content aui-margin-b-15 xhList" id="app" v-cloak>
  <ul class="aui-list aui-media-list">
    <li class="aui-list-item aui-list-item-middle" @click="openDetail('xh', '学会', item.id)" v-for="item in newsList">
      <div class="aui-media-list-item-inner">
        <div class="aui-list-item-media" style="width: 3rem;">
          <img v-if="item.head_pic" :src="item.head_pic" class="aui-img-round aui-list-img-sm">
          <img v-else src="../../image/xs/t1@3x.png" class="aui-img-round aui-list-img-sm">
        </div>
        <div class="aui-list-item-inner">
          <div class="aui-list-item-text">
            <div class="aui-list-item-title aui-font-size-14">{{item.name}}</div>
            <div class="aui-list-item-right">会员数：{{item.headcount}}</div>
          </div>
        </div>
      </div>
    </li>
  </ul>
</div>
</div>
</div>
</section>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script src="../../script/aui-pull-refresh.js"></script>
<script>
apiready = function() {

  var app = new Vue({
    el: '#app',
    data: {
      banner: [],
      newsList: [],
		  page: 1,
      totalpage: 1
    },
    created: function() {
      var $_this = this;

      api.ajax({
        url: window.Url.getGroupList + $_this.page,
        timeout: 300,
      }, function(ret, err) {
          if (ret) {
              // api.alert({ msg: JSON.stringify(ret.data) });
              if (ret.data == null) return
              $_this.totalpage = ret.data.totalpage
              $_this.newsList = ret.data.newsList
          } else {
              api.alert({ msg: JSON.stringify(err) });
          }
      })


      var scroll = new auiScroll({
          listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
          distance:40 //判断到达底部的距离，isToBottom为true
      },function(ret){
         if (ret.isToBottom) {
           $_this.page ++
           if ($_this.page > $_this.totalpage) {
             $_this.page = $_this.totalpage
             return
           }
           api.ajax({
             url: window.Url.getGroupList + $_this.page,
            timeout: 300,
          }, function(ret, err) {
              if (ret) {
                  // api.alert({ msg: JSON.stringify(ret) });
                  $_this.newsList = $_this.newsList.concat(ret.data.newsList)

              } else {
                  api.alert({ msg: JSON.stringify(err) });
              }
          })
         }

      });



    },
    methods: {
      openDetail:function openDetail(type, title, id) {
        api.openWin({
          name: 'index_detail_' + type,
          pageParam: {
            name: 'index_detail_' + type,
            title: title,
            id: id
          },
          url: './first_header.html',
          delay: 200,
          bounces: false
        });
      }
    },
    mounted:function() {
      var $_this = this;
      var pullRefresh = new auiPullToRefresh({
          container: document.querySelector('.aui-refresh-content'),
          triggerDistance: 100
      },function(ret){
          if(ret.status=="success"){
            $_this.page = 1
            api.ajax({
              url: window.Url.getGroupList + $_this.page,
              timeout: 300,
            }, function(ret, err) {
                if (ret) {
                    // api.alert({ msg: JSON.stringify(ret.data) });
                    setTimeout(function() {
                      if (ret.data == null) return
                      $_this.totalpage = ret.data.totalpage
                      $_this.newsList = ret.data.newsList
                      pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                    },500)

                } else {
                    api.alert({ msg: JSON.stringify(err) });
                }
            })
          }
      })
    }
  })
}

</script>
</body>
</html>
